package com.dchh.android.suverynew.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dchh.android.suverynew.R;

import java.util.List;
import java.util.Map;

/**
 * 个人中心菜单
 *
 * @author zhoudan
 * @date 2015年5月29日
 */
public class MenuListAdapter extends BaseAdapter {

    private Activity activity;
    private List<Map<String, String>> list;
    private int[] icons = {R.mipmap.task_package, R.mipmap.download_map, R.mipmap.system_setting};

    public MenuListAdapter(Activity activity, List<Map<String, String>> list) {
        this.activity = activity;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Map<String, String> getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        ViewHolder holder;
        if (row == null) {
            holder = new ViewHolder();
            row = LayoutInflater.from(activity).inflate(R.layout.user_center_nav_list_item, null);
            holder.icon = (ImageView) row.findViewById(R.id.nav_icon);
            holder.text = (TextView) row.findViewById(R.id.nav_name);

            row.setTag(holder);
        } else {
            holder = (ViewHolder) row.getTag();
        }


        holder.icon.setImageDrawable(activity.getResources().getDrawable(icons[position]));
        holder.text.setText(list.get(position).get("name"));

        return row;
    }

    public final class ViewHolder {
        public ImageView icon;
        public TextView text;
    }

}
